package com.my.chapter11;

import java.util.*;
import java.util.Map.Entry;


public class practice23 {
    public static void main(String[] args) {
        Map<Integer, Integer> numsMap = new HashMap<>();
        Random random = new Random();
        for (int i = 0; i < 10000; i++) {
            Integer key = random.nextInt(30);
            Integer vlue = numsMap.get(key);
            numsMap.put(key, vlue == null ? 1 : vlue + 1);

        }
        List<Entry<Integer, Integer>> a = new ArrayList<Entry<Integer, Integer>>(numsMap.entrySet());
        Collections.sort(a, new Comparator<Entry<Integer, Integer>>() {


            @Override
            public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) {
                // TODO Auto-generated method stub
                return o2.getValue() - o1.getValue();
            }
        });
        ;

        for (Entry<Integer, Integer> entry : a) {
            System.out.format("%02d -------------%03d\n", entry.getKey(), entry.getValue());
        }

    }
}
